﻿using Md.Demo.Entity.MongoModels;
using Md.Demo.IBLL;
using Md.Demo.Service;
using Md.Demo.Tools;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace Md.Demo.BLL
{
    public class GreeterApplication : IGreeterApplication
    {

        private readonly IElasticSearchServer _elasticSearchServer;
        public GreeterApplication(IElasticSearchServer elasticSearchServer)
        {
            _elasticSearchServer = elasticSearchServer;
        }

        public async Task<HelloReply> SayHello(HelloRequest request)
        {
            var list = await _elasticSearchServer.ElasticLinqClient.SearchAsync<ExceptionLogger>(
                                   p => p.Index("id").Query(op => op.Match(
                                                   ss => ss.Field(
                                                       qq => qq.message == "this is exception"))));
            var res = list.Documents.ToList();
            return new HelloReply
            {
                Message = "Hello " + request.Name
            };
        }
    }
}
